package com.ktjiaoyu.service.impl;

import com.ktjiaoyu.entity.Supplier;
import com.ktjiaoyu.entity.SysUser;
import com.ktjiaoyu.mapper.SupplierMapper;
import com.ktjiaoyu.mapper.SysUserMapper;
import com.ktjiaoyu.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
//上机2
@Service("supplierService")
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;
    @Override
    public List<Supplier> findList(Supplier supplier) {

        return supplierMapper.getSupplierList(supplier);
    }

    public void setSupplierMapper(SupplierMapper supplierMapper) {
        this.supplierMapper = supplierMapper;
    }
//上机3
    @Override
    @Transactional
    public int saveBatch(List<Supplier> supplierList) {
        int row = 0;
        for (int i = 0; i <supplierList.size() ; i++) {
            //拿出每一条用户数据插入
            Supplier supplier = supplierList.get(i);

            //调用插入数据操作,记录总受影响条数
            row += supplierMapper.addSupplier(supplier);
        }
        return row;
    }

    @Override
    @Transactional
    public int updateSupplier(Supplier supplier) {
        return supplierMapper.updateSupplier(supplier);
    }

    @Override
    @Transactional
    public int deleteSupplier(Long id) {
        return supplierMapper.deleteSupplier(id);
    }
}
